package com.vdong.ai.restful.service.impl;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.vdong.ai.response.VoiceResponse;
import com.vdong.ai.restful.response.Response;
import com.vdong.ai.restful.service.AiVoiceService;
import com.vdong.ai.service.VoiceHttpClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author: liangwei
 */
@Service
public class AiVoiceServiceImpl implements AiVoiceService {

    @Autowired
    VoiceHttpClientService voiceHttpClientService;
    @Qualifier("ObjectMapper")
    @Autowired
    ObjectMapper objectMapper;

    @Override
    public Response Voice(String fileData, String appid, String appkey) {
        String json = voiceHttpClientService.VoiceHttpClient(fileData, appid, appkey);
        VoiceResponse voiceResponsemsg = null;
        try {
            System.out.println(json);
            voiceResponsemsg = objectMapper.readValue(json, VoiceResponse.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return Response.successBean(voiceResponsemsg);

    }
}
